Repository navigation
Conversation
Resolve routing parameter field paths against input messages in gRPC mode so generated Swift transport code handles string, primitive scalar, protobuf enum, and Discovery string enum fields across nested and optional paths while adding required package imports for MemberImportVisibility. For googleapis/google-cloud-swift#1631
There was a problem hiding this comment.
Code Review
This pull request refactors the extraction and formatting of AIP-4222 routing parameters for Swift gRPC clients. It replaces the simple string-based FieldAccessor with a structured FieldSteps slice (using routingFieldStep), allowing robust resolution of nested, optional, and enum field paths. It also introduces comprehensive unit and integration tests to verify routing parameter generation across various scalar, optional, and enum types. The review feedback suggests simplifying the ensureRoutingFieldAnnotated method in internal/sidekick/swift/format_path.go to make it more idiomatic by directly returning the result of c.annotateField.
| func (c *codec) ensureRoutingFieldAnnotated(field *api.Field, modelAnn *modelAnnotations) (*fieldAnnotations, error) { | ||
| fieldAnn, ok := field.Codec().(*fieldAnnotations) | ||
| if !ok { | ||
| if c.Model == nil { | ||
| return nil, fmt.Errorf("internal error: field %s does not have swift fieldAnnotations", field.ID()) | ||
| } | ||
| var err error | ||
| fieldAnn, err = c.annotateField(field, modelAnn) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| return fieldAnn, nil | ||
| } |
There was a problem hiding this comment.
The implementation of ensureRoutingFieldAnnotated can be simplified and made more idiomatic by directly returning the result of c.annotateField if the field is not already annotated, rather than using an explicit var err error declaration and assignment inside the if !ok block.
func (c *codec) ensureRoutingFieldAnnotated(field *api.Field, modelAnn *modelAnnotations) (*fieldAnnotations, error) {
if fieldAnn, ok := field.Codec().(*fieldAnnotations); ok {
return fieldAnn, nil
}
if c.Model == nil {
return nil, fmt.Errorf("internal error: field %s does not have swift fieldAnnotations", field.ID())
}
return c.annotateField(field, modelAnn)
}
Resolve routing parameter field paths against input messages in gRPC mode so generated Swift transport code handles string, primitive scalar, protobuf enum, and Discovery string enum fields across nested and optional paths while adding required package imports for MemberImportVisibility.
For googleapis/google-cloud-swift#1631